<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.List" %>
<%@ page import="org.springframework.context.ApplicationContext" %>
<%@ page import="static org.apache.struts2.ServletActionContext.getServletContext" %>
<%@ page import="org.springframework.web.context.WebApplicationContext" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.ld.xuanKe.service.TeachingClassService" %>
<%@ page import="com.ld.xuanKe.service.impl.TeachingClassServiceImpl" %>
<%@ page import="com.ld.xuanKe.entity.*" %><%--
  Created by IntelliJ IDEA.
  User: 刘邓
  Date: 2023-06-10
  Time: 16:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
  <title>教学班信息</title>
  <link rel="stylesheet" type="text/css" href="/common.css" />
</head>
<body>

<%
  ApplicationContext applicationContext = (ApplicationContext) getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
  TeachingClassService teachingClassService = (TeachingClassServiceImpl) applicationContext.getBean(TeachingClassService.class);
  String courseId0 = request.getParameter("courseId");
  User user = (User)session.getAttribute("user");
  List<TeachingClass> teachings = new ArrayList<>();
  if(courseId0 == null){
    teachings = teachingClassService.list();
  }else {
    try {
      Integer courseId = Integer.parseInt(courseId0);
      teachings = teachingClassService.listByCourseId(courseId);
    } catch (NumberFormatException e) {
      teachings = teachingClassService.list();
    }
  }
  String homePath;
  if (user.getStatus() == 0) {
    homePath = "user";
  } else {
    homePath = "admin";
  }
%>
<a href="/home/<%=homePath%>/index.jsp"
   style="display: inline-block;height: 30px;margin:10px 30px;text-align:center;line-height:30px;background-color:#DDD;text-decoration: none;">返回个人管理页面</a>
<form id='like' action='/home/admin/teachingClass.jsp' method='get'><input name='courseId'>&nbsp&nbsp<input type='submit' value='按课程id查询'>
</form>
<c:if test="<%=teachings.isEmpty()%>">
  <h1 style='width: 80%;height:400px;margin: 0 auto;text-align:center;line-height:400px'>暂无更多信息!</h1>
</c:if>
<c:if test="<%=!teachings.isEmpty()%>">
  <table id='all-request' class='container'>
    <thead>
    <tr>
      <th>教学班id</th>
      <th>课程id</th>
      <th>教学班名称</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="<%=teachings%>" var="teaching">
      <tr>
        <td>${teaching.getId() }</td>
        <td>${teaching.getCourseId()}</td>
        <td>${teaching.getName()}</td>
      </tr>
    </c:forEach>
    </tbody>
  </table>
</c:if>
</body>
<script>
</script>
</html>
